/**
this file is the global direct js
**/
function Haaway(){
	this.author = 'haaway studio';
	this.version = '2012-3';
	
	this.include = function(urls){
		if(typeof urls == 'string'){
			urls = [urls];
		}
		
		var jsfiles = new Array();
		var ext = '';
		for(var i=0; i<urls.length; i++){
			var url = urls[i];
			if(typeof url!='string')
				continue;
			var arr_url = url.split('.');
			ext = arr_url[arr_url.length-1];
			if(ext == 'js'){
				jsfiles.push(url);
			}else if(ext == 'css'){
				document.write('<link type="text/css" rel="stylesheet" href="' + url + '" />');
			}
		}
		for(var i=0; i<jsfiles.length; i++){
			document.write('<script src="' + jsfiles[i] + '"></script>');
		}
	};
	this.load =  function(url, param, callback, beforeSend){
		param = param || {};
		callback = callback || false;
		beforeSend = beforeSend || false;
		$.ajax({
			async	: callback ? true : false,
			beforeSend : function(XMLHttpRequest){
				if(beforeSend) beforeSend(XMLHttpRequest);
			},
			data	: param,
			dataType : 'json',
			success : function(data){
				if(callback && data){
					callback(data);
				}
			},
			timeout : 150000,
			url 	: url
		});
		
	};
		
	this.startup = function(opts){
//		console.debug('我操');
//		this.load('/common/index', '', function(data){
////			console.debug(data);
//		});
	}
	
	
}

Haaway.prototype = {
		
		
		alert	: function(message,callback,width,height,title){
			var title = title || '信息提示';
			var fn = callback || true;
			$.dialog({
				title: title,
				width:width,
				height:height,
			    icon: 'alert.gif',
			    content: message,
				lock: true,
				ok:fn,
				padding: 10,
				maxTop:true
			});
			
		},
		saved: function(message, fn, width, height, title, btn) {
			message = message || '保存数据成功！';
			title = title || '操作成功';
			$.dialog({title: title,width:width,height: height,icon: 'success.gif',content: message,ok: fn,button:btn,okVal: '确定',maxTop:true});
		}, 
		/**
		* 弹出窗
		* @param message 文本/iframe模式的URL
		* @param width 宽
		* @param height 高
		* @param title 标题
		* @param callback 回调
		* @param iframe 为空则为普通模式，否则填iframe的属性，示例：{id: 'iframe01'}
		* @param btn 自定义按钮，示例:[['是','yes'],['否','no'],['取消','cancel']]})
		**/ 
		win: function(message, width, height, title, callback, iframe, btn,fid,lock) {
			message = message || "url:"+iframe;
			fid = fid || 'iframid';
			if(message.indexOf(".htm") > -1){
			message = "url:" + message;
			}
			var parent_win = $.dialog({content: message,width:width,height: height,title: title,ok: callback,button:btn,lock:lock,padding: 0,id:fid});
			return parent_win;
		}
};
var $h = new Haaway();


document.write('<link type="text/css" rel="stylesheet" href="/js/lib/blackbirdjs/blackbird.css" />');
document.write('<link type="text/css" rel="stylesheet" href="/js/lib/lhgdialog/skins/default.css" />');

$h.include([
            '/js/lib/blackbirdjs/blackbird.js',            
            '/js/lib/lhgdialog/lhgdialog.js'
]);
$h.startup({});